﻿using System;
using System.Linq;

namespace Furesoft.Styling
{
    using System.Drawing;
    using System.Windows.Forms;

    using Furesoft.Styling.Converters;
    using ColorConverter = Furesoft.Styling.Converters.ColorConverter;
    using FontConverter = Furesoft.Styling.Converters.FontConverter;
    using PaddingConverter = Furesoft.Styling.Converters.PaddingConverter;
    using SizeConverter = Furesoft.Styling.Converters.SizeConverter;

    public class Converter
    {
        public static object Convert(string s, Type prop, ref bool suceed)
        {
            if (prop.Name == typeof(Padding).Name)
            {
                return new PaddingConverter().Convert(s);
            }
            if (prop.Name == typeof(int).Name)
            {
                return int.Parse(s);
            }
            if (prop.Name == typeof(Size).Name)
            {
                return new SizeConverter().Convert(s);
            }
            else if (prop.Name == typeof(Color).Name)
            {
                return new ColorConverter().Convert(s);
            }
            else if (prop.Name == typeof(Font).Name)
            {
                return new FontConverter().Convert(s);
            }
            else if (prop.Name == typeof(bool).Name)
            {
                return new BoolConverter().Convert(s);
            }
            else if (prop.Name == typeof(Image).Name)
            {
                return s == "null" ? new NullConverter().Convert(s) : new Converters.ImageConverter().Convert(s);
            }
            else if (prop.Name == typeof(string).Name)
            {
                return new StringConverter().Convert(s);
            }
            else if (prop.Name == typeof(Region).Name)
            {
                return new RegionConverter().Convert(s);
            }
            else if (prop.IsEnum)
            {
                return EnumConverter.Convert(prop, s);
            }
            else
            {
                suceed = false;
            }
            return null;
        }
    }
}
